package com.qfedu.service.impl;

import com.qfedu.mapper.StageMapper;
import com.qfedu.model.Stage;
import com.qfedu.page.PageResult;
import com.qfedu.page.QueryPageBean;
import com.qfedu.service.IStageService;
import com.qfedu.utils.UUIDUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

/**
 * 概述:
 *
 * @Author: Tbh
 * @Date: 2022/6/30 20:36
 */

@Service
public class StageServiceImpl implements IStageService {

    @Autowired
    private StageMapper stageMapper;

    @Override
    public PageResult findPage(QueryPageBean queryPage) {
        PageResult pageResult = new PageResult();
        Integer currentPage = queryPage.getCurrentPage();
        Integer pageSize = queryPage.getPageSize();
        List<Stage> page = stageMapper.findPage((currentPage - 1) * pageSize, pageSize);
        Long count = stageMapper.count();
        pageResult.setTotal(count);
        pageResult.setRows(page);
        return pageResult;
    }

    @Override
    @Transactional
    public int addStage(Stage stage) {
        stage.setSid(UUIDUtils.uuid());
        stage.setUpdatetime(new Date());
        int row = stageMapper.addStage(stage);
        return row;
    }

    @Override
    public Stage findBySid(String sid) {
        return stageMapper.findBySid(sid);
    }

    @Override
    @Transactional
    public int edit(Stage stage) {
        int row = stageMapper.updateStage(stage);
        return row;
    }

    @Override
    @Transactional
    public int deleteBySid(String sid) {
        return stageMapper.deleteBySid(sid);
    }
}
